{
  "cells": [
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "## Introduction to Prompt Engineering\n",
        "\n",
        "Below we are loading the necessary libraries, utilities, and configurations.\n",
        "\n",
        "<a href=\"https://colab.research.google.com/github/adithya-s-k/AI-Engineering.academy/blob/main/docs/docs/PromptEngineering/prompt_engineering.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 4,
      "metadata": {},
      "outputs": [
        {
          "name": "stdout",
          "output_type": "stream",
          "text": [
            "Requirement already satisfied: rich in c:\\users\\adithya\\appdata\\roaming\\python\\python311\\site-packages (13.8.1)\n",
            "Requirement already satisfied: markdown-it-py>=2.2.0 in c:\\python311\\lib\\site-packages (from rich) (2.2.0)\n",
            "Requirement already satisfied: pygments<3.0.0,>=2.13.0 in c:\\users\\adithya\\appdata\\roaming\\python\\python311\\site-packages (from rich) (2.14.0)\n",
            "Requirement already satisfied: mdurl~=0.1 in c:\\python311\\lib\\site-packages (from markdown-it-py>=2.2.0->rich) (0.1.2)\n"
          ]
        }
      ],
      "source": [
        "# !pip install openai\n",
        "# !pip install python-dotenv\n",
        "# !pip install rich"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "for the following guide we will be using [groq](https://console.groq.com/) - llama3-70b-8192\n",
        "which is open ai api compatible"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 5,
      "metadata": {},
      "outputs": [],
      "source": [
        "import os\n",
        "import openai\n",
        "from rich import print\n",
        "from dotenv import load_dotenv\n",
        "\n",
        "load_dotenv()\n",
        "\n",
        "local_api_key = os.getenv(\"GROQ_API_KEY\")\n",
        "# openai.api_key = os.getenv(\"GROQ_API_KEY\")\n",
        "\n",
        "client = openai.OpenAI(\n",
        "    base_url=\"https://api.groq.com/openai/v1\",\n",
        "    api_key=local_api_key\n",
        ")"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": []
    },
    {
      "cell_type": "code",
      "execution_count": 6,
      "metadata": {},
      "outputs": [
        {
          "data": {
            "text/html": [
              "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"><span style=\"color: #800080; text-decoration-color: #800080; font-weight: bold\">ChatCompletion</span><span style=\"font-weight: bold\">(</span>\n",
              "    <span style=\"color: #808000; text-decoration-color: #808000\">id</span>=<span style=\"color: #008000; text-decoration-color: #008000\">'chatcmpl-6b95d260-1414-4fbb-ba11-5a0fa9a7ab1d'</span>,\n",
              "    <span style=\"color: #808000; text-decoration-color: #808000\">choices</span>=<span style=\"font-weight: bold\">[</span>\n",
              "        <span style=\"color: #800080; text-decoration-color: #800080; font-weight: bold\">Choice</span><span style=\"font-weight: bold\">(</span>\n",
              "            <span style=\"color: #808000; text-decoration-color: #808000\">finish_reason</span>=<span style=\"color: #008000; text-decoration-color: #008000\">'stop'</span>,\n",
              "            <span style=\"color: #808000; text-decoration-color: #808000\">index</span>=<span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">0</span>,\n",
              "            <span style=\"color: #808000; text-decoration-color: #808000\">logprobs</span>=<span style=\"color: #800080; text-decoration-color: #800080; font-style: italic\">None</span>,\n",
              "            <span style=\"color: #808000; text-decoration-color: #808000\">message</span>=<span style=\"color: #800080; text-decoration-color: #800080; font-weight: bold\">ChatCompletionMessage</span><span style=\"font-weight: bold\">(</span>\n",
              "                <span style=\"color: #808000; text-decoration-color: #808000\">content</span>=<span style=\"color: #008000; text-decoration-color: #008000\">\"The creation of black holes is a fascinating topic in the realm of astrophysics. A black </span>\n",
              "<span style=\"color: #008000; text-decoration-color: #008000\">hole is a region in spacetime where the gravitational pull is so strong that nothing, including light, can escape. </span>\n",
              "<span style=\"color: #008000; text-decoration-color: #008000\">The formation of a black hole typically occurs when a massive star undergoes a catastrophic collapse, resulting in </span>\n",
              "<span style=\"color: #008000; text-decoration-color: #008000\">a singularity.\\n\\nThe process begins when a massive star, typically with a mass greater than three times that of </span>\n",
              "<span style=\"color: #008000; text-decoration-color: #008000\">the sun, exhausts its fuel supply and reaches the end of its life cycle. As the star's core contracts, its density </span>\n",
              "<span style=\"color: #008000; text-decoration-color: #008000\">increases, causing a massive amount of matter to be compressed into an incredibly small region. This compression </span>\n",
              "<span style=\"color: #008000; text-decoration-color: #008000\">releases an enormous amount of energy, causing a supernova explosion.\\n\\nIf the star is massive enough, the core </span>\n",
              "<span style=\"color: #008000; text-decoration-color: #008000\">will collapse into a singularity, creating a black hole. The point of singularity is characterized by infinite </span>\n",
              "<span style=\"color: #008000; text-decoration-color: #008000\">density and zero volume, where the laws of physics as we know them break down. The event horizon, which marks the </span>\n",
              "<span style=\"color: #008000; text-decoration-color: #008000\">boundary of the black hole, is the point of no return, beyond which anything that enters cannot escape.\\n\\nThere </span>\n",
              "<span style=\"color: #008000; text-decoration-color: #008000\">are several ways in which black holes can form, including:\\n\\n1. Stellar collapse: As mentioned earlier, the </span>\n",
              "<span style=\"color: #008000; text-decoration-color: #008000\">collapse of a massive star can create a black hole.\\n2. Mergers: The merger of two neutron stars or black holes can</span>\n",
              "<span style=\"color: #008000; text-decoration-color: #008000\">also create a more massive black hole.\\n3. Primordial black holes: Some theories suggest that black holes could </span>\n",
              "<span style=\"color: #008000; text-decoration-color: #008000\">have formed in the early universe, during the Big Bang, through the collapse of density fluctuations.\\n\\nThe </span>\n",
              "<span style=\"color: #008000; text-decoration-color: #008000\">detection of black holes is challenging due to their small size and the fact that they do not emit any radiation. </span>\n",
              "<span style=\"color: #008000; text-decoration-color: #008000\">However, scientists have developed various methods to detect black holes, including:\\n\\n1. X-ray and gamma-ray </span>\n",
              "<span style=\"color: #008000; text-decoration-color: #008000\">observations: Telescopes can detect X-rays and gamma-rays emitted by hot gas swirling around black holes.\\n2. Radio</span>\n",
              "<span style=\"color: #008000; text-decoration-color: #008000\">and optical observations: Radio and optical telescopes can detect radiation emitted by matter as it spirals into a </span>\n",
              "<span style=\"color: #008000; text-decoration-color: #008000\">black hole.\\n3. Gravitational waves: The detection of gravitational waves by LIGO and VIRGO collaboration in 2015 </span>\n",
              "<span style=\"color: #008000; text-decoration-color: #008000\">provided strong evidence for the existence of black holes.\\n\\nIn conclusion, the creation of black holes is a </span>\n",
              "<span style=\"color: #008000; text-decoration-color: #008000\">complex and fascinating process that involves the collapse of massive stars or the merger of compact objects. The </span>\n",
              "<span style=\"color: #008000; text-decoration-color: #008000\">detection of black holes is an active area of research, with scientists using a variety of methods to study these </span>\n",
              "<span style=\"color: #008000; text-decoration-color: #008000\">enigmatic objects.\"</span>,\n",
              "                <span style=\"color: #808000; text-decoration-color: #808000\">refusal</span>=<span style=\"color: #800080; text-decoration-color: #800080; font-style: italic\">None</span>,\n",
              "                <span style=\"color: #808000; text-decoration-color: #808000\">role</span>=<span style=\"color: #008000; text-decoration-color: #008000\">'assistant'</span>,\n",
              "                <span style=\"color: #808000; text-decoration-color: #808000\">function_call</span>=<span style=\"color: #800080; text-decoration-color: #800080; font-style: italic\">None</span>,\n",
              "                <span style=\"color: #808000; text-decoration-color: #808000\">tool_calls</span>=<span style=\"color: #800080; text-decoration-color: #800080; font-style: italic\">None</span>\n",
              "            <span style=\"font-weight: bold\">)</span>\n",
              "        <span style=\"font-weight: bold\">)</span>\n",
              "    <span style=\"font-weight: bold\">]</span>,\n",
              "    <span style=\"color: #808000; text-decoration-color: #808000\">created</span>=<span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">1729072028</span>,\n",
              "    <span style=\"color: #808000; text-decoration-color: #808000\">model</span>=<span style=\"color: #008000; text-decoration-color: #008000\">'llama3-8b-8192'</span>,\n",
              "    <span style=\"color: #808000; text-decoration-color: #808000\">object</span>=<span style=\"color: #008000; text-decoration-color: #008000\">'chat.completion'</span>,\n",
              "    <span style=\"color: #808000; text-decoration-color: #808000\">service_tier</span>=<span style=\"color: #800080; text-decoration-color: #800080; font-style: italic\">None</span>,\n",
              "    <span style=\"color: #808000; text-decoration-color: #808000\">system_fingerprint</span>=<span style=\"color: #008000; text-decoration-color: #008000\">'fp_6a6771ae9c'</span>,\n",
              "    <span style=\"color: #808000; text-decoration-color: #808000\">usage</span>=<span style=\"color: #800080; text-decoration-color: #800080; font-weight: bold\">CompletionUsage</span><span style=\"font-weight: bold\">(</span>\n",
              "        <span style=\"color: #808000; text-decoration-color: #808000\">completion_tokens</span>=<span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">488</span>,\n",
              "        <span style=\"color: #808000; text-decoration-color: #808000\">prompt_tokens</span>=<span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">76</span>,\n",
              "        <span style=\"color: #808000; text-decoration-color: #808000\">total_tokens</span>=<span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">564</span>,\n",
              "        <span style=\"color: #808000; text-decoration-color: #808000\">queue_time</span>=<span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">0.015080524</span>,\n",
              "        <span style=\"color: #808000; text-decoration-color: #808000\">prompt_time</span>=<span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">0.009203864</span>,\n",
              "        <span style=\"color: #808000; text-decoration-color: #808000\">completion_time</span>=<span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">0.406666667</span>,\n",
              "        <span style=\"color: #808000; text-decoration-color: #808000\">total_time</span>=<span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">0.415870531</span>\n",
              "    <span style=\"font-weight: bold\">)</span>,\n",
              "    <span style=\"color: #808000; text-decoration-color: #808000\">x_groq</span>=<span style=\"font-weight: bold\">{</span><span style=\"color: #008000; text-decoration-color: #008000\">'id'</span>: <span style=\"color: #008000; text-decoration-color: #008000\">'req_01jaabjpmke6gbkr1fm4rkj769'</span><span style=\"font-weight: bold\">}</span>\n",
              "<span style=\"font-weight: bold\">)</span>\n",
              "</pre>\n"
            ],
            "text/plain": [
              "\u001b[1;35mChatCompletion\u001b[0m\u001b[1m(\u001b[0m\n",
              "    \u001b[33mid\u001b[0m=\u001b[32m'chatcmpl-6b95d260-1414-4fbb-ba11-5a0fa9a7ab1d'\u001b[0m,\n",
              "    \u001b[33mchoices\u001b[0m=\u001b[1m[\u001b[0m\n",
              "        \u001b[1;35mChoice\u001b[0m\u001b[1m(\u001b[0m\n",
              "            \u001b[33mfinish_reason\u001b[0m=\u001b[32m'stop'\u001b[0m,\n",
              "            \u001b[33mindex\u001b[0m=\u001b[1;36m0\u001b[0m,\n",
              "            \u001b[33mlogprobs\u001b[0m=\u001b[3;35mNone\u001b[0m,\n",
              "            \u001b[33mmessage\u001b[0m=\u001b[1;35mChatCompletionMessage\u001b[0m\u001b[1m(\u001b[0m\n",
              "                \u001b[33mcontent\u001b[0m=\u001b[32m\"The\u001b[0m\u001b[32m creation of black holes is a fascinating topic in the realm of astrophysics. A black \u001b[0m\n",
              "\u001b[32mhole is a region in spacetime where the gravitational pull is so strong that nothing, including light, can escape. \u001b[0m\n",
              "\u001b[32mThe formation of a black hole typically occurs when a massive star undergoes a catastrophic collapse, resulting in \u001b[0m\n",
              "\u001b[32ma singularity.\\n\\nThe process begins when a massive star, typically with a mass greater than three times that of \u001b[0m\n",
              "\u001b[32mthe sun, exhausts its fuel supply and reaches the end of its life cycle. As the star's core contracts, its density \u001b[0m\n",
              "\u001b[32mincreases, causing a massive amount of matter to be compressed into an incredibly small region. This compression \u001b[0m\n",
              "\u001b[32mreleases an enormous amount of energy, causing a supernova explosion.\\n\\nIf the star is massive enough, the core \u001b[0m\n",
              "\u001b[32mwill collapse into a singularity, creating a black hole. The point of singularity is characterized by infinite \u001b[0m\n",
              "\u001b[32mdensity and zero volume, where the laws of physics as we know them break down. The event horizon, which marks the \u001b[0m\n",
              "\u001b[32mboundary of the black hole, is the point of no return, beyond which anything that enters cannot escape.\\n\\nThere \u001b[0m\n",
              "\u001b[32mare several ways in which black holes can form, including:\\n\\n1. Stellar collapse: As mentioned earlier, the \u001b[0m\n",
              "\u001b[32mcollapse of a massive star can create a black hole.\\n2. Mergers: The merger of two neutron stars or black holes can\u001b[0m\n",
              "\u001b[32malso create a more massive black hole.\\n3. Primordial black holes: Some theories suggest that black holes could \u001b[0m\n",
              "\u001b[32mhave formed in the early universe, during the Big Bang, through the collapse of density fluctuations.\\n\\nThe \u001b[0m\n",
              "\u001b[32mdetection of black holes is challenging due to their small size and the fact that they do not emit any radiation. \u001b[0m\n",
              "\u001b[32mHowever, scientists have developed various methods to detect black holes, including:\\n\\n1. X-ray and gamma-ray \u001b[0m\n",
              "\u001b[32mobservations: Telescopes can detect X-rays and gamma-rays emitted by hot gas swirling around black holes.\\n2. Radio\u001b[0m\n",
              "\u001b[32mand optical observations: Radio and optical telescopes can detect radiation emitted by matter as it spirals into a \u001b[0m\n",
              "\u001b[32mblack hole.\\n3. Gravitational waves: The detection of gravitational waves by LIGO and VIRGO collaboration in 2015 \u001b[0m\n",
              "\u001b[32mprovided strong evidence for the existence of black holes.\\n\\nIn conclusion, the creation of black holes is a \u001b[0m\n",
              "\u001b[32mcomplex and fascinating process that involves the collapse of massive stars or the merger of compact objects. The \u001b[0m\n",
              "\u001b[32mdetection of black holes is an active area of research, with scientists using a variety of methods to study these \u001b[0m\n",
              "\u001b[32menigmatic objects.\"\u001b[0m,\n",
              "                \u001b[33mrefusal\u001b[0m=\u001b[3;35mNone\u001b[0m,\n",
              "                \u001b[33mrole\u001b[0m=\u001b[32m'assistant'\u001b[0m,\n",
              "                \u001b[33mfunction_call\u001b[0m=\u001b[3;35mNone\u001b[0m,\n",
              "                \u001b[33mtool_calls\u001b[0m=\u001b[3;35mNone\u001b[0m\n",
              "            \u001b[1m)\u001b[0m\n",
              "        \u001b[1m)\u001b[0m\n",
              "    \u001b[1m]\u001b[0m,\n",
              "    \u001b[33mcreated\u001b[0m=\u001b[1;36m1729072028\u001b[0m,\n",
              "    \u001b[33mmodel\u001b[0m=\u001b[32m'llama3-8b-8192'\u001b[0m,\n",
              "    \u001b[33mobject\u001b[0m=\u001b[32m'chat.completion'\u001b[0m,\n",
              "    \u001b[33mservice_tier\u001b[0m=\u001b[3;35mNone\u001b[0m,\n",
              "    \u001b[33msystem_fingerprint\u001b[0m=\u001b[32m'fp_6a6771ae9c'\u001b[0m,\n",
              "    \u001b[33musage\u001b[0m=\u001b[1;35mCompletionUsage\u001b[0m\u001b[1m(\u001b[0m\n",
              "        \u001b[33mcompletion_tokens\u001b[0m=\u001b[1;36m488\u001b[0m,\n",
              "        \u001b[33mprompt_tokens\u001b[0m=\u001b[1;36m76\u001b[0m,\n",
              "        \u001b[33mtotal_tokens\u001b[0m=\u001b[1;36m564\u001b[0m,\n",
              "        \u001b[33mqueue_time\u001b[0m=\u001b[1;36m0\u001b[0m\u001b[1;36m.015080524\u001b[0m,\n",
              "        \u001b[33mprompt_time\u001b[0m=\u001b[1;36m0\u001b[0m\u001b[1;36m.009203864\u001b[0m,\n",
              "        \u001b[33mcompletion_time\u001b[0m=\u001b[1;36m0\u001b[0m\u001b[1;36m.406666667\u001b[0m,\n",
              "        \u001b[33mtotal_time\u001b[0m=\u001b[1;36m0\u001b[0m\u001b[1;36m.415870531\u001b[0m\n",
              "    \u001b[1m)\u001b[0m,\n",
              "    \u001b[33mx_groq\u001b[0m=\u001b[1m{\u001b[0m\u001b[32m'id'\u001b[0m: \u001b[32m'req_01jaabjpmke6gbkr1fm4rkj769'\u001b[0m\u001b[1m}\u001b[0m\n",
              "\u001b[1m)\u001b[0m\n"
            ]
          },
          "metadata": {},
          "output_type": "display_data"
        }
      ],
      "source": [
        "# MODEL = \"gpt-3.5-turbo\"\n",
        "\n",
        "# response = client.chat.completions.create(\n",
        "#     model=MODEL,\n",
        "#     messages=[\n",
        "#         {\"role\": \"system\", \"content\": \"You are an AI research assistant. You use a tone that is technical and scientific.\"},\n",
        "#         {\"role\": \"user\", \"content\": \"Hello, who are you?\"},\n",
        "#         {\"role\": \"assistant\", \"content\": \"Greeting! I am an AI research assistant. How can I help you today?\"},\n",
        "#         {\"role\": \"user\", \"content\": \"Can you tell me about the creation of black holes?\"}\n",
        "#     ],\n",
        "#     temperature=0,\n",
        "# )\n",
        "\n",
        "MODEL = \"llama3-8b-8192\"\n",
        "\n",
        "response = client.chat.completions.create(\n",
        "    model=MODEL,\n",
        "    messages=[\n",
        "        {\"role\": \"system\", \"content\": \"You are an AI research assistant. You use a tone that is technical and scientific.\"},\n",
        "        {\"role\": \"user\", \"content\": \"Hello, who are you?\"},\n",
        "        {\"role\": \"assistant\", \"content\": \"Greeting! I am an AI research assistant. How can I help you today?\"},\n",
        "        {\"role\": \"user\", \"content\": \"Can you tell me about the creation of black holes?\"}\n",
        "    ],\n",
        "    temperature=0,\n",
        ")\n",
        "\n",
        "print(response)"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 16,
      "metadata": {},
      "outputs": [
        {
          "data": {
            "text/html": [
              "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\">The creation of black holes is a fascinating topic in the realm of astrophysics. A black hole is a region in \n",
              "spacetime where the gravitational pull is so strong that nothing, including light, can escape. The formation of a \n",
              "black hole typically occurs when a massive star undergoes a catastrophic collapse, resulting in a singularity.\n",
              "\n",
              "The process begins when a massive star, typically with a mass greater than three times that of the sun, exhausts \n",
              "its fuel supply and reaches the end of its life cycle. As the star's core contracts, its density increases, causing\n",
              "a massive amount of matter to be compressed into an incredibly small region. This compression releases an enormous \n",
              "amount of energy, causing a supernova explosion.\n",
              "\n",
              "If the star is massive enough, the core will collapse into a singularity, creating a black hole. The point of \n",
              "singularity is characterized by infinite density and zero volume, where the laws of physics as we know them break \n",
              "down. The event horizon, which marks the boundary of the black hole, is the point of no return, beyond which \n",
              "anything that enters cannot escape.\n",
              "\n",
              "There are several ways in which black holes can form, including:\n",
              "\n",
              "<span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">1</span>. Stellar collapse: As mentioned earlier, the collapse of a massive star can create a black hole.\n",
              "<span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">2</span>. Mergers: The merger of two neutron stars or black holes can also create a more massive black hole.\n",
              "<span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">3</span>. Primordial black holes: Some theories suggest that black holes could have formed in the early universe, during \n",
              "the Big Bang, through the collapse of density fluctuations.\n",
              "\n",
              "The detection of black holes is challenging due to their small size and the fact that they do not emit any \n",
              "radiation. However, scientists have developed various methods to detect black holes, including:\n",
              "\n",
              "<span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">1</span>. X-ray and gamma-ray observations: Telescopes can detect X-rays and gamma-rays emitted by hot gas swirling around\n",
              "black holes.\n",
              "<span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">2</span>. Radio and optical observations: Radio and optical telescopes can detect radiation emitted by matter as it \n",
              "spirals into a black hole.\n",
              "<span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">3</span>. Gravitational waves: The detection of gravitational waves by LIGO and VIRGO collaboration in <span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">2015</span> provided \n",
              "strong evidence for the existence of black holes.\n",
              "\n",
              "In conclusion, the creation of black holes is a complex and fascinating process that involves the collapse of \n",
              "massive stars or the merger of compact objects. The detection of black holes is an active area of research, with \n",
              "scientists using a variety of methods to study these enigmatic objects.\n",
              "</pre>\n"
            ],
            "text/plain": [
              "The creation of black holes is a fascinating topic in the realm of astrophysics. A black hole is a region in \n",
              "spacetime where the gravitational pull is so strong that nothing, including light, can escape. The formation of a \n",
              "black hole typically occurs when a massive star undergoes a catastrophic collapse, resulting in a singularity.\n",
              "\n",
              "The process begins when a massive star, typically with a mass greater than three times that of the sun, exhausts \n",
              "its fuel supply and reaches the end of its life cycle. As the star's core contracts, its density increases, causing\n",
              "a massive amount of matter to be compressed into an incredibly small region. This compression releases an enormous \n",
              "amount of energy, causing a supernova explosion.\n",
              "\n",
              "If the star is massive enough, the core will collapse into a singularity, creating a black hole. The point of \n",
              "singularity is characterized by infinite density and zero volume, where the laws of physics as we know them break \n",
              "down. The event horizon, which marks the boundary of the black hole, is the point of no return, beyond which \n",
              "anything that enters cannot escape.\n",
              "\n",
              "There are several ways in which black holes can form, including:\n",
              "\n",
              "\u001b[1;36m1\u001b[0m. Stellar collapse: As mentioned earlier, the collapse of a massive star can create a black hole.\n",
              "\u001b[1;36m2\u001b[0m. Mergers: The merger of two neutron stars or black holes can also create a more massive black hole.\n",
              "\u001b[1;36m3\u001b[0m. Primordial black holes: Some theories suggest that black holes could have formed in the early universe, during \n",
              "the Big Bang, through the collapse of density fluctuations.\n",
              "\n",
              "The detection of black holes is challenging due to their small size and the fact that they do not emit any \n",
              "radiation. However, scientists have developed various methods to detect black holes, including:\n",
              "\n",
              "\u001b[1;36m1\u001b[0m. X-ray and gamma-ray observations: Telescopes can detect X-rays and gamma-rays emitted by hot gas swirling around\n",
              "black holes.\n",
              "\u001b[1;36m2\u001b[0m. Radio and optical observations: Radio and optical telescopes can detect radiation emitted by matter as it \n",
              "spirals into a black hole.\n",
              "\u001b[1;36m3\u001b[0m. Gravitational waves: The detection of gravitational waves by LIGO and VIRGO collaboration in \u001b[1;36m2015\u001b[0m provided \n",
              "strong evidence for the existence of black holes.\n",
              "\n",
              "In conclusion, the creation of black holes is a complex and fascinating process that involves the collapse of \n",
              "massive stars or the merger of compact objects. The detection of black holes is an active area of research, with \n",
              "scientists using a variety of methods to study these enigmatic objects.\n"
            ]
          },
          "metadata": {},
          "output_type": "display_data"
        }
      ],
      "source": [
        "print(response.choices[0].message.content)"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 38,
      "metadata": {},
      "outputs": [],
      "source": [
        "def get_completion(messages, model=\"llama-3.2-90b-text-preview\", temperature=0, max_tokens=4000):\n",
        "    response = client.chat.completions.create(\n",
        "        model=model,\n",
        "        messages=messages,\n",
        "        temperature=temperature,\n",
        "        max_tokens=max_tokens,\n",
        "    )\n",
        "    \n",
        "    return response.choices[0].message.content"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "## Basic prompt example:"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 39,
      "metadata": {},
      "outputs": [
        {
          "data": {
            "text/html": [
              "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\">blue.\n",
              "</pre>\n"
            ],
            "text/plain": [
              "blue.\n"
            ]
          },
          "metadata": {},
          "output_type": "display_data"
        }
      ],
      "source": [
        "prompt = \"The sky is\"\n",
        "\n",
        "message = [\n",
        "    {\n",
        "        \"role\": \"user\",\n",
        "        \"content\": prompt\n",
        "    }\n",
        "]\n",
        "\n",
        "response = get_completion(message)\n",
        "print(response)"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 40,
      "metadata": {},
      "outputs": [
        {
          "data": {
            "text/html": [
              "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\">blue.\n",
              "</pre>\n"
            ],
            "text/plain": [
              "blue.\n"
            ]
          },
          "metadata": {},
          "output_type": "display_data"
        }
      ],
      "source": [
        "response = get_completion(message,temperature=0.5)\n",
        "print(response)"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "## Text Summarization"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 20,
      "metadata": {},
      "outputs": [
        {
          "data": {
            "text/html": [
              "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\">Antibiotics are medications that kill or prevent bacterial growth, allowing the body's immune system to fight off \n",
              "infections, but are ineffective against viral infections and can lead to antibiotic resistance if used \n",
              "inappropriately.\n",
              "</pre>\n"
            ],
            "text/plain": [
              "Antibiotics are medications that kill or prevent bacterial growth, allowing the body's immune system to fight off \n",
              "infections, but are ineffective against viral infections and can lead to antibiotic resistance if used \n",
              "inappropriately.\n"
            ]
          },
          "metadata": {},
          "output_type": "display_data"
        }
      ],
      "source": [
        "prompt = \"\"\"Antibiotics are a type of medication used to treat bacterial infections. They work by either killing the bacteria or preventing them from reproducing, allowing the body's immune system to fight off the infection. Antibiotics are usually taken orally in the form of pills, capsules, or liquid solutions, or sometimes administered intravenously. They are not effective against viral infections, and using them inappropriately can lead to antibiotic resistance. \n",
        "\n",
        "Explain the above in one sentence:\"\"\"\n",
        "\n",
        "message = [\n",
        "    {   \n",
        "        \"role\": \"user\",\n",
        "        \"content\": prompt\n",
        "    }\n",
        "]\n",
        "\n",
        "response = get_completion(message, temperature=0)\n",
        "print(response)"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 21,
      "metadata": {},
      "outputs": [
        {
          "data": {
            "text/html": [
              "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\">Antibiotics are medications that kill or prevent bacterial growth, allowing the body's immune system to fight off \n",
              "infections, but are ineffective against viral infections and can lead to antibiotic resistance if used \n",
              "inappropriately.\n",
              "</pre>\n"
            ],
            "text/plain": [
              "Antibiotics are medications that kill or prevent bacterial growth, allowing the body's immune system to fight off \n",
              "infections, but are ineffective against viral infections and can lead to antibiotic resistance if used \n",
              "inappropriately.\n"
            ]
          },
          "metadata": {},
          "output_type": "display_data"
        }
      ],
      "source": [
        "prompt = \"\"\"\n",
        "Your task is to summarize an abstract into one sentence. \n",
        "\n",
        "Abstract: Antibiotics are a type of medication used to treat bacterial infections. They work by either killing the bacteria or preventing them from reproducing, allowing the body's immune system to fight off the infection. Antibiotics are usually taken orally in the form of pills, capsules, or liquid solutions, or sometimes administered intravenously. They are not effective against viral infections, and using them inappropriately can lead to antibiotic resistance.\n",
        "\"\"\"\n",
        "\n",
        "message = [\n",
        "    {   \n",
        "        \"role\": \"user\",\n",
        "        \"content\": prompt\n",
        "    }\n",
        "]\n",
        "\n",
        "response = get_completion(message, temperature=0)\n",
        "print(response)"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 22,
      "metadata": {},
      "outputs": [
        {
          "data": {
            "text/html": [
              "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\">Antibiotics are medicines that help the body fight off bacterial infections by killing or stopping the growth of \n",
              "the bacteria, and they come in different forms such as pills, liquids, or injections.\n",
              "</pre>\n"
            ],
            "text/plain": [
              "Antibiotics are medicines that help the body fight off bacterial infections by killing or stopping the growth of \n",
              "the bacteria, and they come in different forms such as pills, liquids, or injections.\n"
            ]
          },
          "metadata": {},
          "output_type": "display_data"
        }
      ],
      "source": [
        "prompt = \"\"\"\n",
        "Your task is to summarize an abstract into one sentence. \n",
        "\n",
        "Avoid technical jargon and explain it in the simplest of words.\n",
        "\n",
        "Abstract: Antibiotics are a type of medication used to treat bacterial infections. They work by either killing the bacteria or preventing them from reproducing, allowing the body's immune system to fight off the infection. Antibiotics are usually taken orally in the form of pills, capsules, or liquid solutions, or sometimes administered intravenously. They are not effective against viral infections, and using them inappropriately can lead to antibiotic resistance.\n",
        "\"\"\"\n",
        "\n",
        "message = [\n",
        "    {   \n",
        "        \"role\": \"user\",\n",
        "        \"content\": prompt\n",
        "    }\n",
        "]\n",
        "\n",
        "response = get_completion(message, temperature=0)\n",
        "print(response)"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "## Question Answering"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 23,
      "metadata": {},
      "outputs": [
        {
          "data": {
            "text/html": [
              "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\">Mice\n",
              "</pre>\n"
            ],
            "text/plain": [
              "Mice\n"
            ]
          },
          "metadata": {},
          "output_type": "display_data"
        }
      ],
      "source": [
        "prompt = \"\"\"Answer the question based on the context below. Keep the answer short and concise. Respond \"Unsure about answer\" if not sure about the answer.\n",
        "\n",
        "Context: Teplizumab traces its roots to a New Jersey drug company called Ortho Pharmaceutical. There, scientists generated an early version of the antibody, dubbed OKT3. Originally sourced from mice, the molecule was able to bind to the surface of T cells and limit their cell-killing potential. In 1986, it was approved to help prevent organ rejection after kidney transplants, making it the first therapeutic antibody allowed for human use.\n",
        "\n",
        "Question: What was OKT3 originally sourced from?\n",
        "\n",
        "Answer:\n",
        "\"\"\"\n",
        "\n",
        "message = [\n",
        "    {\n",
        "        \"role\": \"user\",\n",
        "        \"content\": prompt\n",
        "    }\n",
        "]\n",
        "\n",
        "response = get_completion(message)\n",
        "print(response)"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "## Text Classification"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 24,
      "metadata": {},
      "outputs": [
        {
          "data": {
            "text/html": [
              "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\">Neutral\n",
              "</pre>\n"
            ],
            "text/plain": [
              "Neutral\n"
            ]
          },
          "metadata": {},
          "output_type": "display_data"
        }
      ],
      "source": [
        "user_input = \"I think the food was okay\"\n",
        "\n",
        "prompt = \"\"\"Classify the text into neutral, negative or positive. The input text will be delimited by ```\n",
        "\n",
        "Text: ```{user_input}```\n",
        "\n",
        "Sentiment:\"\"\"\n",
        "\n",
        "message = [\n",
        "    {\n",
        "        \"role\": \"user\",\n",
        "        \"content\": prompt.format(user_input=user_input)\n",
        "    }\n",
        "]\n",
        "\n",
        "response = get_completion(message)\n",
        "print(response)"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "## Information Extraction"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 25,
      "metadata": {},
      "outputs": [
        {
          "data": {
            "text/html": [
              "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"><span style=\"font-weight: bold\">[</span><span style=\"color: #008000; text-decoration-color: #008000\">\"LLaMA\"</span>, <span style=\"color: #008000; text-decoration-color: #008000\">\"Alpaca\"</span><span style=\"font-weight: bold\">]</span>\n",
              "</pre>\n"
            ],
            "text/plain": [
              "\u001b[1m[\u001b[0m\u001b[32m\"LLaMA\"\u001b[0m, \u001b[32m\"Alpaca\"\u001b[0m\u001b[1m]\u001b[0m\n"
            ]
          },
          "metadata": {},
          "output_type": "display_data"
        }
      ],
      "source": [
        "prompt = \"\"\"Your task is to extract model names from machine learning paper abstracts. Your response is an array of the model names in the format [\\\"model_name\\\"]. If you don't find model names in the abstract or you are not sure, return [\\\"NA\\\"].\n",
        "\n",
        "Abstract: Large Language Models (LLMs), such as ChatGPT and GPT-4, have revolutionized natural language processing research and demonstrated potential in Artificial General Intelligence (AGI). However, the expensive training and deployment of LLMs present challenges to transparent and open academic research. To address these issues, this project open-sources the Chinese LLaMA and Alpaca…\n",
        "\n",
        "Tags:\"\"\"\n",
        "\n",
        "message = [\n",
        "    {\n",
        "        \"role\": \"user\",\n",
        "        \"content\": prompt\n",
        "    }\n",
        "]\n",
        "\n",
        "response = get_completion(message)\n",
        "print(response)"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "## Machine Translation"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 26,
      "metadata": {},
      "outputs": [
        {
          "data": {
            "text/html": [
              "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\">The translation of <span style=\"color: #008000; text-decoration-color: #008000\">\"Glad to be here!\"</span> from English to Spanish is:\n",
              "\n",
              "¡Encantado de estar aquí!\n",
              "\n",
              "Note: If you want to use a more informal tone, you can use:\n",
              "\n",
              "¡Estoy encantado de estar aquí!\n",
              "\n",
              "Or:\n",
              "\n",
              "¡Me alegra estar aquí!\n",
              "</pre>\n"
            ],
            "text/plain": [
              "The translation of \u001b[32m\"Glad to be here!\"\u001b[0m from English to Spanish is:\n",
              "\n",
              "¡Encantado de estar aquí!\n",
              "\n",
              "Note: If you want to use a more informal tone, you can use:\n",
              "\n",
              "¡Estoy encantado de estar aquí!\n",
              "\n",
              "Or:\n",
              "\n",
              "¡Me alegra estar aquí!\n"
            ]
          },
          "metadata": {},
          "output_type": "display_data"
        }
      ],
      "source": [
        "prompt = \"\"\"Translate the following from English to Spanish:\n",
        "“Glad to be here!”\n",
        "\"\"\"\n",
        "\n",
        "message = [\n",
        "    {   \n",
        "        \"role\": \"user\",\n",
        "        \"content\": prompt\n",
        "    }\n",
        "]\n",
        "\n",
        "response = get_completion(message)\n",
        "print(response)"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "## Tone Transformation"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 27,
      "metadata": {},
      "outputs": [
        {
          "data": {
            "text/html": [
              "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\">Here's the translation:\n",
              "\n",
              "<span style=\"color: #008000; text-decoration-color: #008000\">\"WOOHOO! Thrilled to be here and can't wait to get started!\"</span>\n",
              "</pre>\n"
            ],
            "text/plain": [
              "Here's the translation:\n",
              "\n",
              "\u001b[32m\"WOOHOO! Thrilled to be here and can't wait to get started!\"\u001b[0m\n"
            ]
          },
          "metadata": {},
          "output_type": "display_data"
        }
      ],
      "source": [
        "prompt = \"\"\"Translate the following from happy to super excited:\n",
        "“Glad to be here!”\n",
        "\"\"\"\n",
        "\n",
        "message = [\n",
        "    {\n",
        "        \"role\": \"user\",\n",
        "        \"content\": prompt\n",
        "    }\n",
        "]\n",
        "\n",
        "response = get_completion(message)\n",
        "print(response)"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "## Role Playing"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 28,
      "metadata": {},
      "outputs": [
        {
          "data": {
            "text/html": [
              "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\">A fascinating topic! The creation of black holes is a complex process that involves the collapse of massive stars \n",
              "or the merger of compact objects such as neutron stars or black holes themselves.\n",
              "\n",
              "In the case of stellar-mass black holes, they are formed when a massive star with a mass at least three times that \n",
              "of the sun runs out of fuel and collapses under its own gravity. If the star is massive enough, its gravity will \n",
              "overcome the pressure of its own nuclear reactions, causing a supernova explosion. However, if the star is not \n",
              "massive enough to trigger a supernova, it will collapse directly into a black hole.\n",
              "\n",
              "The collapse is a rapid process, occurring over a timescale of milliseconds. As the star collapses, its density and\n",
              "gravity increase, causing a singularity to form at its center. The point of singularity is characterized by \n",
              "infinite density and zero volume, and it is surrounded by an event horizon, which marks the boundary beyond which \n",
              "nothing, not even light, can escape the gravitational pull of the black hole.\n",
              "\n",
              "In the case of supermassive black holes, they are thought to have formed in the early universe through the merger \n",
              "of smaller black holes or the collapse of a massive cloud of gas and dust. These black holes can have masses \n",
              "millions or even billions of times that of the sun and are found at the centers of many galaxies, including our own\n",
              "Milky Way.\n",
              "\n",
              "It's worth noting that the formation of black holes is still an active area of research, and there are many open \n",
              "questions and uncertainties in our current understanding of the process. However, the basic principles outlined \n",
              "above provide a good starting point for understanding how black holes are created.\n",
              "</pre>\n"
            ],
            "text/plain": [
              "A fascinating topic! The creation of black holes is a complex process that involves the collapse of massive stars \n",
              "or the merger of compact objects such as neutron stars or black holes themselves.\n",
              "\n",
              "In the case of stellar-mass black holes, they are formed when a massive star with a mass at least three times that \n",
              "of the sun runs out of fuel and collapses under its own gravity. If the star is massive enough, its gravity will \n",
              "overcome the pressure of its own nuclear reactions, causing a supernova explosion. However, if the star is not \n",
              "massive enough to trigger a supernova, it will collapse directly into a black hole.\n",
              "\n",
              "The collapse is a rapid process, occurring over a timescale of milliseconds. As the star collapses, its density and\n",
              "gravity increase, causing a singularity to form at its center. The point of singularity is characterized by \n",
              "infinite density and zero volume, and it is surrounded by an event horizon, which marks the boundary beyond which \n",
              "nothing, not even light, can escape the gravitational pull of the black hole.\n",
              "\n",
              "In the case of supermassive black holes, they are thought to have formed in the early universe through the merger \n",
              "of smaller black holes or the collapse of a massive cloud of gas and dust. These black holes can have masses \n",
              "millions or even billions of times that of the sun and are found at the centers of many galaxies, including our own\n",
              "Milky Way.\n",
              "\n",
              "It's worth noting that the formation of black holes is still an active area of research, and there are many open \n",
              "questions and uncertainties in our current understanding of the process. However, the basic principles outlined \n",
              "above provide a good starting point for understanding how black holes are created.\n"
            ]
          },
          "metadata": {},
          "output_type": "display_data"
        }
      ],
      "source": [
        "prompt = \"\"\"The following is a conversation with an AI research assistant. The assistant tone is technical and scientific.\n",
        "\n",
        "Human: Hello, who are you?\n",
        "AI: Greeting! I am an AI research assistant. How can I help you today?\n",
        "Human: Can you tell me about the creation of black holes?\n",
        "AI:\"\"\"\n",
        "\n",
        "message = [\n",
        "    {\n",
        "        \"role\": \"user\",\n",
        "        \"content\": prompt\n",
        "    }\n",
        "]\n",
        "\n",
        "response = get_completion(message)\n",
        "print(response)"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 29,
      "metadata": {},
      "outputs": [
        {
          "data": {
            "text/html": [
              "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\">A fascinating topic! The creation of black holes is a complex and multifaceted process that has been extensively \n",
              "studied in the fields of astrophysics and theoretical physics.\n",
              "\n",
              "Black holes are regions in spacetime where the gravitational pull is so strong that nothing, including light, can \n",
              "escape once it falls within a certain radius, known as the event horizon. The formation of a black hole typically \n",
              "occurs when a massive star undergoes a catastrophic collapse, resulting in a singularity at its center.\n",
              "\n",
              "There are several ways in which a massive star can collapse to form a black hole. One scenario is known as the \n",
              "direct collapse, where the star's core collapses under its own gravity, causing a massive amount of matter to be \n",
              "compressed into an incredibly small region. This compression creates an intense gravitational field, which warps \n",
              "the fabric of spacetime around the star, forming the event horizon.\n",
              "\n",
              "Another scenario is the indirect collapse, where the star undergoes a supernova explosion, expelling a significant \n",
              "amount of its mass and energy. If the star is massive enough, the remaining core can collapse into a black hole.\n",
              "\n",
              "The formation of a black hole also depends on the star's mass and metallicity. More massive stars are more likely \n",
              "to form black holes, as they have a greater amount of energy to be released during their collapse. Additionally, \n",
              "stars with lower metallicity <span style=\"font-weight: bold\">(</span>i.e., fewer elements heavier than hydrogen and helium<span style=\"font-weight: bold\">)</span> are more likely to form black \n",
              "holes, as they have a lower opacity and can collapse more easily.\n",
              "\n",
              "Once a black hole is formed, it can continue to grow through the accretion of surrounding matter and energy. This \n",
              "process can lead to the formation of an accretion disk, which is a swirling disk of hot, dense gas that surrounds \n",
              "the black hole. The accretion disk can emit intense radiation, including X-rays and gamma rays, which can be \n",
              "detected by telescopes.\n",
              "\n",
              "In summary, the creation of black holes is a complex process that involves the collapse of massive stars, the \n",
              "compression of matter into an incredibly small region, and the warping of spacetime around the star. The formation \n",
              "of black holes depends on various factors, including the star's mass, metallicity, and the presence of an accretion\n",
              "disk.\n",
              "\n",
              "Would you like me to elaborate on any specific aspect of black hole formation or evolution?\n",
              "</pre>\n"
            ],
            "text/plain": [
              "A fascinating topic! The creation of black holes is a complex and multifaceted process that has been extensively \n",
              "studied in the fields of astrophysics and theoretical physics.\n",
              "\n",
              "Black holes are regions in spacetime where the gravitational pull is so strong that nothing, including light, can \n",
              "escape once it falls within a certain radius, known as the event horizon. The formation of a black hole typically \n",
              "occurs when a massive star undergoes a catastrophic collapse, resulting in a singularity at its center.\n",
              "\n",
              "There are several ways in which a massive star can collapse to form a black hole. One scenario is known as the \n",
              "direct collapse, where the star's core collapses under its own gravity, causing a massive amount of matter to be \n",
              "compressed into an incredibly small region. This compression creates an intense gravitational field, which warps \n",
              "the fabric of spacetime around the star, forming the event horizon.\n",
              "\n",
              "Another scenario is the indirect collapse, where the star undergoes a supernova explosion, expelling a significant \n",
              "amount of its mass and energy. If the star is massive enough, the remaining core can collapse into a black hole.\n",
              "\n",
              "The formation of a black hole also depends on the star's mass and metallicity. More massive stars are more likely \n",
              "to form black holes, as they have a greater amount of energy to be released during their collapse. Additionally, \n",
              "stars with lower metallicity \u001b[1m(\u001b[0mi.e., fewer elements heavier than hydrogen and helium\u001b[1m)\u001b[0m are more likely to form black \n",
              "holes, as they have a lower opacity and can collapse more easily.\n",
              "\n",
              "Once a black hole is formed, it can continue to grow through the accretion of surrounding matter and energy. This \n",
              "process can lead to the formation of an accretion disk, which is a swirling disk of hot, dense gas that surrounds \n",
              "the black hole. The accretion disk can emit intense radiation, including X-rays and gamma rays, which can be \n",
              "detected by telescopes.\n",
              "\n",
              "In summary, the creation of black holes is a complex process that involves the collapse of massive stars, the \n",
              "compression of matter into an incredibly small region, and the warping of spacetime around the star. The formation \n",
              "of black holes depends on various factors, including the star's mass, metallicity, and the presence of an accretion\n",
              "disk.\n",
              "\n",
              "Would you like me to elaborate on any specific aspect of black hole formation or evolution?\n"
            ]
          },
          "metadata": {},
          "output_type": "display_data"
        }
      ],
      "source": [
        "system_message = \"\"\"\n",
        "The following is a conversation with an AI research assistant. The assistant tone is technical and scientific.\n",
        "\"\"\"\n",
        "\n",
        "prompt = \"\"\"\n",
        "Human: Hello, who are you?\n",
        "AI: Greeting! I am an AI research assistant. How can I help you today?\n",
        "Human: Can you tell me about the creation of black holes?\n",
        "AI:\n",
        "\"\"\"\n",
        "\n",
        "messages = [\n",
        "    {   \n",
        "        \"role\": \"system\",\n",
        "        \"content\": system_message\n",
        "    },\n",
        "    {\n",
        "        \"role\": \"user\",\n",
        "        \"content\": prompt\n",
        "    }\n",
        "]\n",
        "\n",
        "response = get_completion(messages)\n",
        "print(response)"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 30,
      "metadata": {},
      "outputs": [
        {
          "data": {
            "text/html": [
              "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\">The creation of black holes is a fascinating topic in astrophysics. A black hole is a region in space where the \n",
              "gravitational pull is so strong that nothing, including light, can escape. It is formed when a massive star \n",
              "collapses in on itself and its gravity becomes so strong that it warps the fabric of spacetime around it.\n",
              "\n",
              "The process of black hole formation typically begins with the death of a massive star. When a star with a mass at \n",
              "least three times that of the sun runs out of fuel, it collapses under its own gravity. If the star is massive \n",
              "enough, its gravity will be so strong that it will cause a massive amount of matter to be compressed into an \n",
              "incredibly small point, known as a singularity.\n",
              "\n",
              "At this point, the star's gravity becomes so strong that it warps the fabric of spacetime around it, creating a \n",
              "boundary called the event horizon. Once something crosses the event horizon, it is trapped by the black hole's \n",
              "gravity and cannot escape.\n",
              "\n",
              "The formation of a black hole is a complex process that involves the collapse of a massive star, the creation of a \n",
              "singularity, and the warping of spacetime around it. It is a fascinating area of study in astrophysics, and \n",
              "scientists continue to learn more about black holes and their role in the universe.\n",
              "\n",
              "Would you like to know more about black holes or is there something specific you would like to know?\n",
              "</pre>\n"
            ],
            "text/plain": [
              "The creation of black holes is a fascinating topic in astrophysics. A black hole is a region in space where the \n",
              "gravitational pull is so strong that nothing, including light, can escape. It is formed when a massive star \n",
              "collapses in on itself and its gravity becomes so strong that it warps the fabric of spacetime around it.\n",
              "\n",
              "The process of black hole formation typically begins with the death of a massive star. When a star with a mass at \n",
              "least three times that of the sun runs out of fuel, it collapses under its own gravity. If the star is massive \n",
              "enough, its gravity will be so strong that it will cause a massive amount of matter to be compressed into an \n",
              "incredibly small point, known as a singularity.\n",
              "\n",
              "At this point, the star's gravity becomes so strong that it warps the fabric of spacetime around it, creating a \n",
              "boundary called the event horizon. Once something crosses the event horizon, it is trapped by the black hole's \n",
              "gravity and cannot escape.\n",
              "\n",
              "The formation of a black hole is a complex process that involves the collapse of a massive star, the creation of a \n",
              "singularity, and the warping of spacetime around it. It is a fascinating area of study in astrophysics, and \n",
              "scientists continue to learn more about black holes and their role in the universe.\n",
              "\n",
              "Would you like to know more about black holes or is there something specific you would like to know?\n"
            ]
          },
          "metadata": {},
          "output_type": "display_data"
        }
      ],
      "source": [
        "system_message = \"\"\"\n",
        "The following is a conversation with an AI research assistant. The assistant tone is technical and scientific.\n",
        "\"\"\"\n",
        "\n",
        "user_message_1 = \"\"\"\n",
        "Hello, who are you?\n",
        "\"\"\"\n",
        "\n",
        "ai_message_1 = \"\"\"\n",
        "Greeting! I am an AI research assistant. How can I help you today?\n",
        "\"\"\"\n",
        "\n",
        "prompt = \"\"\"\n",
        "Human: Can you tell me about the creation of blackholes?\n",
        "AI:\n",
        "\"\"\"\n",
        "\n",
        "messages = [\n",
        "    {   \n",
        "        \"role\": \"system\",\n",
        "        \"content\": system_message\n",
        "    },\n",
        "    {\n",
        "        \"role\": \"user\",\n",
        "        \"content\": user_message_1\n",
        "    },\n",
        "    {\n",
        "        \"role\": \"assistant\",\n",
        "        \"content\": ai_message_1\n",
        "\n",
        "    },\n",
        "    {\n",
        "        \"role\": \"user\",\n",
        "        \"content\": prompt\n",
        "    }\n",
        "]\n",
        "\n",
        "response = get_completion(messages)\n",
        "print(response)"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "## Code Generation"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 31,
      "metadata": {},
      "outputs": [
        {
          "data": {
            "text/html": [
              "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\">Here is the MySQL query to get all students in the Computer Science Department:\n",
              "\n",
              "```sql\n",
              "SELECT s.*\n",
              "FROM students s\n",
              "JOIN departments d ON s.DepartmentId = d.DepartmentId\n",
              "WHERE d.DepartmentName = <span style=\"color: #008000; text-decoration-color: #008000\">'Computer Science'</span>;\n",
              "```\n",
              "\n",
              "This query joins the `students` table with the `departments` table on the `DepartmentId` column. Then it filters \n",
              "the results to only include rows where the `DepartmentName` is <span style=\"color: #008000; text-decoration-color: #008000\">'Computer Science'</span>. The `s.*` in the `SELECT` clause\n",
              "means to select all columns from the `students` table.\n",
              "</pre>\n"
            ],
            "text/plain": [
              "Here is the MySQL query to get all students in the Computer Science Department:\n",
              "\n",
              "```sql\n",
              "SELECT s.*\n",
              "FROM students s\n",
              "JOIN departments d ON s.DepartmentId = d.DepartmentId\n",
              "WHERE d.DepartmentName = \u001b[32m'Computer Science'\u001b[0m;\n",
              "```\n",
              "\n",
              "This query joins the `students` table with the `departments` table on the `DepartmentId` column. Then it filters \n",
              "the results to only include rows where the `DepartmentName` is \u001b[32m'Computer Science'\u001b[0m. The `s.*` in the `SELECT` clause\n",
              "means to select all columns from the `students` table.\n"
            ]
          },
          "metadata": {},
          "output_type": "display_data"
        }
      ],
      "source": [
        "prompt = \"\\\"\\\"\\\"\\nTable departments, columns = [DepartmentId, DepartmentName]\\nTable students, columns = [DepartmentId, StudentId, StudentName]\\nCreate a MySQL query for all students in the Computer Science Department\\n\\\"\\\"\\\"\"\n",
        "\n",
        "message = [\n",
        "    {\n",
        "        \"role\": \"user\",\n",
        "        \"content\": prompt\n",
        "    }\n",
        "]\n",
        "\n",
        "response = get_completion(message)\n",
        "print(response)"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "## Reasoning "
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 32,
      "metadata": {},
      "outputs": [
        {
          "data": {
            "text/html": [
              "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\">Let's break down the problem step by step:\n",
              "\n",
              "Step <span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">1</span>: Identify the odd numbers in the group:\n",
              "\n",
              "The odd numbers in the group are: <span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">15</span>, <span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">5</span>, <span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">13</span>, <span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">7</span>, and <span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">1</span>.\n",
              "\n",
              "Step <span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">2</span>: Add the odd numbers:\n",
              "\n",
              "<span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">15</span> + <span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">5</span> + <span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">13</span> + <span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">7</span> + <span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">1</span> = <span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">42</span>\n",
              "\n",
              "Step <span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">3</span>: Determine whether the result is odd or even:\n",
              "\n",
              "The result, <span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">42</span>, is an even number.\n",
              "\n",
              "Therefore, the statement <span style=\"color: #008000; text-decoration-color: #008000\">\"The odd numbers in this group add up to an even number\"</span> is true.\n",
              "</pre>\n"
            ],
            "text/plain": [
              "Let's break down the problem step by step:\n",
              "\n",
              "Step \u001b[1;36m1\u001b[0m: Identify the odd numbers in the group:\n",
              "\n",
              "The odd numbers in the group are: \u001b[1;36m15\u001b[0m, \u001b[1;36m5\u001b[0m, \u001b[1;36m13\u001b[0m, \u001b[1;36m7\u001b[0m, and \u001b[1;36m1\u001b[0m.\n",
              "\n",
              "Step \u001b[1;36m2\u001b[0m: Add the odd numbers:\n",
              "\n",
              "\u001b[1;36m15\u001b[0m + \u001b[1;36m5\u001b[0m + \u001b[1;36m13\u001b[0m + \u001b[1;36m7\u001b[0m + \u001b[1;36m1\u001b[0m = \u001b[1;36m42\u001b[0m\n",
              "\n",
              "Step \u001b[1;36m3\u001b[0m: Determine whether the result is odd or even:\n",
              "\n",
              "The result, \u001b[1;36m42\u001b[0m, is an even number.\n",
              "\n",
              "Therefore, the statement \u001b[32m\"The odd numbers in this group add up to an even number\"\u001b[0m is true.\n"
            ]
          },
          "metadata": {},
          "output_type": "display_data"
        }
      ],
      "source": [
        "prompt = \"\"\"The odd numbers in this group add up to an even number: 15, 32, 5, 13, 82, 7, 1. \n",
        "\n",
        "Solve by breaking the problem into steps. First, identify the odd numbers, add them, and indicate whether the result is odd or even.\"\"\"\n",
        "\n",
        "message = [\n",
        "    {\n",
        "        \"role\": \"user\",\n",
        "        \"content\": prompt\n",
        "    }\n",
        "]\n",
        "\n",
        "response = get_completion(message)\n",
        "print(response)"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "## Advanced Prompting Techniques"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "### Few-shot prompts"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 36,
      "metadata": {},
      "outputs": [
        {
          "data": {
            "text/html": [
              "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\">Let's add up the odd numbers in the group: <span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">15</span> + <span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">5</span> + <span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">13</span> + <span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">7</span> + <span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">1</span> = <span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">41</span>. Since <span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">41</span> is an odd number, the statement is \n",
              "<span style=\"color: #ff0000; text-decoration-color: #ff0000; font-style: italic\">False</span>.\n",
              "\n",
              "So, the correct answer is:\n",
              "\n",
              "A: The answer is <span style=\"color: #ff0000; text-decoration-color: #ff0000; font-style: italic\">False</span>.\n",
              "</pre>\n"
            ],
            "text/plain": [
              "Let's add up the odd numbers in the group: \u001b[1;36m15\u001b[0m + \u001b[1;36m5\u001b[0m + \u001b[1;36m13\u001b[0m + \u001b[1;36m7\u001b[0m + \u001b[1;36m1\u001b[0m = \u001b[1;36m41\u001b[0m. Since \u001b[1;36m41\u001b[0m is an odd number, the statement is \n",
              "\u001b[3;91mFalse\u001b[0m.\n",
              "\n",
              "So, the correct answer is:\n",
              "\n",
              "A: The answer is \u001b[3;91mFalse\u001b[0m.\n"
            ]
          },
          "metadata": {},
          "output_type": "display_data"
        }
      ],
      "source": [
        "prompt = \"\"\"The odd numbers in this group add up to an even number: 4, 8, 9, 15, 12, 2, 1.\n",
        "A: The answer is False.\n",
        "\n",
        "The odd numbers in this group add up to an even number: 17,  10, 19, 4, 8, 12, 24.\n",
        "A: The answer is True.\n",
        "\n",
        "The odd numbers in this group add up to an even number: 16,  11, 14, 4, 8, 13, 24.\n",
        "A: The answer is True.\n",
        "\n",
        "The odd numbers in this group add up to an even number: 17,  9, 10, 12, 13, 4, 2.\n",
        "A: The answer is False.\n",
        "\n",
        "The odd numbers in this group add up to an even number: 15, 32, 5, 13, 82, 7, 1. \n",
        "A:\"\"\"\n",
        "\n",
        "messages = [\n",
        "    {\n",
        "        \"role\": \"user\",\n",
        "        \"content\": prompt\n",
        "    }\n",
        "]\n",
        "\n",
        "response = get_completion(messages)\n",
        "print(response)"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "## Chain-of-Throught (CoT) Prompting"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 35,
      "metadata": {},
      "outputs": [
        {
          "data": {
            "text/html": [
              "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\">Let's add up the odd numbers: <span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">15</span>, <span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">5</span>, <span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">13</span>, <span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">7</span>, <span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">1</span> = <span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">41</span>. The answer is <span style=\"color: #ff0000; text-decoration-color: #ff0000; font-style: italic\">False</span>.\n",
              "</pre>\n"
            ],
            "text/plain": [
              "Let's add up the odd numbers: \u001b[1;36m15\u001b[0m, \u001b[1;36m5\u001b[0m, \u001b[1;36m13\u001b[0m, \u001b[1;36m7\u001b[0m, \u001b[1;36m1\u001b[0m = \u001b[1;36m41\u001b[0m. The answer is \u001b[3;91mFalse\u001b[0m.\n"
            ]
          },
          "metadata": {},
          "output_type": "display_data"
        }
      ],
      "source": [
        "prompt = \"\"\"The odd numbers in this group add up to an even number: 4, 8, 9, 15, 12, 2, 1.\n",
        "A: Adding all the odd numbers (9, 15, 1) gives 25. The answer is False.\n",
        "\n",
        "The odd numbers in this group add up to an even number: 15, 32, 5, 13, 82, 7, 1. \n",
        "A:\"\"\"\n",
        "\n",
        "messages = [\n",
        "    {\n",
        "        \"role\": \"user\",\n",
        "        \"content\": prompt\n",
        "    }\n",
        "]\n",
        "\n",
        "response = get_completion(messages)\n",
        "print(response)"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "## Zero Shot CoT"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 37,
      "metadata": {},
      "outputs": [
        {
          "data": {
            "text/html": [
              "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\">Let's break it down step by step:\n",
              "\n",
              "<span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">1</span>. You started with <span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">10</span> apples.\n",
              "<span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">2</span>. You gave <span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">2</span> apples to the neighbor, so you have <span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">10</span> - <span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">2</span> = <span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">8</span> apples left.\n",
              "<span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">3</span>. You gave <span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">2</span> apples to the repairman, so you have <span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">8</span> - <span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">2</span> = <span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">6</span> apples left.\n",
              "<span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">4</span>. You bought <span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">5</span> more apples, so you now have <span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">6</span> + <span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">5</span> = <span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">11</span> apples.\n",
              "<span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">5</span>. You ate <span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">1</span> apple, so you have <span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">11</span> - <span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">1</span> = <span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">10</span> apples left.\n",
              "\n",
              "So, you remain with <span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">10</span> apples.\n",
              "</pre>\n"
            ],
            "text/plain": [
              "Let's break it down step by step:\n",
              "\n",
              "\u001b[1;36m1\u001b[0m. You started with \u001b[1;36m10\u001b[0m apples.\n",
              "\u001b[1;36m2\u001b[0m. You gave \u001b[1;36m2\u001b[0m apples to the neighbor, so you have \u001b[1;36m10\u001b[0m - \u001b[1;36m2\u001b[0m = \u001b[1;36m8\u001b[0m apples left.\n",
              "\u001b[1;36m3\u001b[0m. You gave \u001b[1;36m2\u001b[0m apples to the repairman, so you have \u001b[1;36m8\u001b[0m - \u001b[1;36m2\u001b[0m = \u001b[1;36m6\u001b[0m apples left.\n",
              "\u001b[1;36m4\u001b[0m. You bought \u001b[1;36m5\u001b[0m more apples, so you now have \u001b[1;36m6\u001b[0m + \u001b[1;36m5\u001b[0m = \u001b[1;36m11\u001b[0m apples.\n",
              "\u001b[1;36m5\u001b[0m. You ate \u001b[1;36m1\u001b[0m apple, so you have \u001b[1;36m11\u001b[0m - \u001b[1;36m1\u001b[0m = \u001b[1;36m10\u001b[0m apples left.\n",
              "\n",
              "So, you remain with \u001b[1;36m10\u001b[0m apples.\n"
            ]
          },
          "metadata": {},
          "output_type": "display_data"
        }
      ],
      "source": [
        "prompt = \"\"\"I went to the market and bought 10 apples. I gave 2 apples to the neighbor and 2 to the repairman. I then went and bought 5 more apples and ate 1. How many apples did I remain with?\n",
        "\n",
        "Let's think step by step.\"\"\"\n",
        "\n",
        "messages = [\n",
        "    {\n",
        "        \"role\": \"user\",\n",
        "        \"content\": prompt\n",
        "    }\n",
        "]\n",
        "\n",
        "response = get_completion(messages)\n",
        "print(response)"
      ]
    }
  ],
  "metadata": {
    "kernelspec": {
      "display_name": "Python 3",
      "language": "python",
      "name": "python3"
    },
    "language_info": {
      "codemirror_mode": {
        "name": "ipython",
        "version": 3
      },
      "file_extension": ".py",
      "mimetype": "text/x-python",
      "name": "python",
      "nbconvert_exporter": "python",
      "pygments_lexer": "ipython3",
      "version": "3.11.0"
    }
  },
  "nbformat": 4,
  "nbformat_minor": 2
}
